package api;


import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.SneakyThrows;
import model.UserInfo;
import util.AppVar;
import util.DBUtils;
import util.ResultUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 根据文章id设置作者详情
 */
public class GetUserByAidServlet extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String msg = "未知错误！";
        UserInfo userInfo = new UserInfo();
        //1.得到前端的数据并校验
        String aidStr = req.getParameter("aid");
        if (!StrUtil.isBlank(aidStr)) {
            int aid=Integer.valueOf(aidStr);
            if(aid>0){
                //2.查询数据库，并组织返回数据
                Connection connection= DBUtils.getConnection();
                String sql = "select * from userinfo where ())";
                PreparedStatement statement = connection.prepareStatement(sql);
                statement.setInt(1,aid);
                ResultSet resultSet=(statement.executeQuery());


                }
            }else{
            msg="非法错误";

        }


        //3/将前面查询到的数据返回给前端
        resp.setContentType(AppVar.RESPONSE_CONTENTTYPE_JSON);
        resp.getWriter().println(JSONUtil.toJsonStr(ResultUtils.toResult(200, userInfo, msg)));
    }
}
